package com.inexas.cu.server.register;

import static org.junit.Assert.*;
import org.junit.*;
import com.google.inject.*;
import com.inexas.cu.client.pipe.*;
import com.inexas.cu.client.register.*;
import com.inexas.cu.server.*;

public class BuildTestAccountProvider {
	private final static String defaultFirstName = "First";
	private final static String defaultLastName = "Last";
	private final static String defaultAccountName = "testaccountname";
	private final static String defaultPassword = "testpassword";
	private Injector factory;
    private AccountProvider accountProvider;

	@Before
	public void setup() {
		factory = Guice.createInjector(new TestModule());
		accountProvider = factory.getInstance(AccountProvider.class);
	}

	private AbstractResponse createDefaultAccount() {
		final Register register = new Register(	//
				defaultFirstName, defaultLastName,	//
				defaultAccountName, defaultPassword);
		return accountProvider.service(register);
	}

	@Test
	public void createAccount() {
		final AbstractResponse result = createDefaultAccount();
		assertNull(result.getErrorMessage());
	}
	
	@Test
	public void signIn() {
		createAccount();
		final SignIn signInRequest = new SignIn(defaultAccountName, defaultPassword);
		final CurrentUser currentUser = (CurrentUser)accountProvider.service(signInRequest);
		assertNull(currentUser.getErrorMessage());
	}

}
